/*
 * Copyright (c) 2006 Sun Microsystems, Inc.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.sunspotworld;

import edu.ncsu.util.TimeConstants;
import com.sun.spot.edemo.EDemoBoard;
import com.sun.spot.edemo.peripheral.EDemoSerial;
import edu.ncsu.gps.GPSReader;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import java.io.DataInputStream;


/*
 * The startApp method of this class is called by the VM to start the
 * application.
 *
 * The manifest specifies this class as MIDlet-1, which means it will
 * be selected for execution.
 *
 * Demo interfacing to a GPS unit.
 *
 */

public class StartApplication extends MIDlet {

    private EDemoSerial serial = new EDemoSerial();
    private DataInputStream dio;
    private boolean reading = false;

    
    private static final long SAMPLE_INTERVAL = /*1*TimeConstants.MINUTES +*/ 10*TimeConstants.SECONDS;

    protected void startApp() throws MIDletStateChangeException {
        System.out.println("GPS Demo...");
        while (EDemoBoard.getInstance().getSwitches()[0].isOpen()) {
            GPSReader.getInstance().takeReading(SAMPLE_INTERVAL);
        }
        notifyDestroyed();
    }

    protected void pauseApp() {
        // This will never be called by the Squawk VM
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        // Only called if startApp throws any exception other than MIDletStateChangeException
    }
}
